package com.example.Lezedata.ui.dataPage;

import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.Lezedata.R;

class DataViewModel {
    public String title;
    public String value;
    public DataViewModel(String title , String value){
        this.title = title;
        this.value = value;
    }
}

public class DataView extends LinearLayout {

    public TextView title;
    public TextView value;
    public DataViewModel model;

    public static DataView newInstance(Context context) {
        DataView dataView = (DataView)LayoutInflater.from(context).inflate(R.layout.data_page_dataview,null,false);
        return dataView;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        title = findViewById(R.id.title);
        value = findViewById(R.id.value);
    }

    public DataView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setModel(DataViewModel model) {
        this.model = model;
        refresh();
    }

    public void refresh(){
        title.setText(model.title);
        value.setText(model.value);
    }
}
